isf 0.1.0

Parsing, Deserialization and Serialization of the Interactive Shader Format.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
/*
{
  "CATEGORIES" : [
    "Color"
  ],
  "DESCRIPTION" : "",
  "ISFVSN" : "2",
  "INPUTS" : [
    {
      "LABELS" : [
      	"Custom Input",
        "Newton",
        "Castel",
        "Field",
        "Jameson",
        "Seemann",
        "Rimington",
        "Bishop",
        "Helmholtz",
        "Scriabin",
        "Klein",
        "Aeppli",
        "Belmont",
        "Zieverink"
      ],
      "NAME" : "iAuthor",
      "TYPE" : "long",
      "LABEL" : "Author",
      "VALUES" : [
        0,
        1,
        2,
        3,
        4,
        5,
        6,
        7,
        8,
        9,
        10,
        11,
        12,
        13
      ]
    },
	{
		"NAME": "iBaseCustomColor",
		"TYPE": "color",
		"DEFAULT": [
			0.25,
			0.59,
			0.9,
			1.0
		]
	},
	{
		"NAME": "iColorMode",
		"TYPE": "long",
		"VALUES": [
			0,
			1,
			2,
			3,
			4,
			5,
			6
		],
		"LABELS": [
			"Basic Complementary",
			"Split Complementary",
			"Compound Complementary",
			"Spectrum",
			"Shades",
			"Analogous",
			"Compound Analogous"
		],
		"DEFAULT": 0
	},
    {
      "NAME" : "note0",
      "TYPE" : "bool",
      "DEFAULT" : 0
    },
    {
      "NAME" : "note1",
      "TYPE" : "bool",
      "DEFAULT" : 0
    },
    {
      "NAME" : "note2",
      "TYPE" : "bool",
      "DEFAULT" : 0
    },
    {
      "NAME" : "note3",
      "TYPE" : "bool",
      "DEFAULT" : 0
    },
    {
      "NAME" : "note4",
      "TYPE" : "bool",
      "DEFAULT" : 0
    },
    {
      "NAME" : "note5",
      "TYPE" : "bool",
      "DEFAULT" : 0
    },
    {
      "NAME" : "note6",
      "TYPE" : "bool",
      "DEFAULT" : 0
    },
    {
      "NAME" : "note7",
      "TYPE" : "bool",
      "DEFAULT" : 0
    },
    {
      "NAME" : "note8",
      "TYPE" : "bool",
      "DEFAULT" : 0
    },
    {
      "NAME" : "note9",
      "TYPE" : "bool",
      "DEFAULT" : 0
    },
    {
      "NAME" : "note10",
      "TYPE" : "bool",
      "DEFAULT" : 0
    },
    {
      "NAME" : "note11",
      "TYPE" : "bool",
      "DEFAULT" : 0
    }
  ],
  "CREDIT" : "VIDVOX"
}
*/


/*
//	Color Scales via http://rhythmiclight.com/archives/ideas/colorscales.html
C C# D D# E F F# G G# A A# B 
Newton • red • orange • yellow • green • blue • indigo • violet (Gerstner, p.167)
Castel • blue • blue-green • green • olive green • yellow • yellow-orange • orange • red • crimson • violet • agate • indigo (Peacock, p.400)
Field • blue • purple • red • orange • yellow • yellow green • green (Klein, p.69)
Jameson • red • red-orange • orange • orange-yellow • yellow • green • green-blue • blue • blue-purple • purple • purple-violet • violet (Jameson, p.12)
Seemann • carmine • scarlet • orange • yellow-orange • yellow • green • green blue • blue • indigo • violet • brown • black (Klein, p.86)
Rimington • deep red • crimson • orange-crimson • orange • yellow • yellow-green • green • blueish green • blue-green • indigo • deep blue • violet (Peacock, p.402)
Bishop • red • orange-red or scarlet • orange • gold or yellow-orange • yellow or green-gold • yellow-green • green • greenish-blue or aquamarine • blue • indigo or violet-blue • violet • violet-red • red (Bishop, p.11)
Helmholtz • yellow • green • greenish blue • cayan-blue • indigo blue • violet • end of red • red • red • red • red orange • orange (Helmholtz, p.22)
Scriabin • red • violet • yellow • steely with the glint of metal • pearly blue the shimmer of moonshine • dark red • bright blue • rosy orange • purple • green • steely with a glint of metal • pearly blue the shimmer of moonshine (Jones, p.104)
Klein • dark red • red • red orange • orange • yellow • yellow green • green • blue-green • blue • blue violet • violet • dark violet (Klein, p.209)
Aeppli • red • orange • yellow • green • blue-green • ultramarine blue • violet • purple (Gerstner, p.169)
Belmont • red • red-orange • orange • yellow-orange • yellow • yellow-green • green • blue-green • blue • blue-violet • violet • red-violet (Belmont, p.226)
Zieverink • yellow/green • green • blue/green • blue • indigo • violet • ultra violet • infra red • red • orange • yellow/white • yellow (Cincinnati Contemporary Art Center)
*/

const vec3 red = vec3(231.0/255.0,52.0/255.0,39.0/255.0);
const vec3 orange = vec3(234.0/255.0,134.0/255.0,54.0/255.0);
const vec3 yellow = vec3(245.0/255.0,243.0/255.0,98.0/255.0);
const vec3 green = vec3(64.0/255.0,141.0/255.0,64.0/255.0);
const vec3 blue = vec3(25.0/255.0,19.0/255.0,125.0/255.0);

const vec3 indigo = vec3(117.0/255.0,28.0/255.0,120.0/255.0);
const vec3 violet = vec3(199.0/255.0,49.0/255.0,132.0/255.0);

const vec3 bluegreen = vec3(66.0/255.0,142.0/255.0,129.0/255.0);
const vec3 olivegreen = vec3(119.0/255.0,144.0/255.0,57.0/255.0);
const vec3 yelloworange = vec3(240.0/255.0,210.0/255.0,90.0/255.0);
const vec3 crimson = vec3(148.0/255.0,33.0/255.0,23.0/255.0);
const vec3 agate = vec3(69.0/255.0,23.0/255.0,120.0/255.0);

const vec3 purple = vec3(117.0/255.0,28.0/255.0,120.0/255.0);
const vec3 yellowgreen = vec3(119.0/255.0,144.0/255.0,57.0/255.0);
const vec3 redorange = vec3(227.0/255.0,85.0/255.0,44.0/255.0);
const vec3 orangeyellow = vec3(240.0/255.0,210.0/255.0,90.0/255.0);
const vec3 greenblue = vec3(66.0/255.0,142.0/255.0,129.0/255.0);
const vec3 bluepurple = vec3(69.0/255.0,23.0/255.0,120.0/255.0);
const vec3 purpleviolet = vec3(153.0/255.0,41.0/255.0,130.0/255.0);
const vec3 carmine = vec3(98.0/255.0,34.0/255.0,31.0/255.0);
const vec3 scarlet = vec3(231.0/255.0,52.0/255.0,39.0/255.0);
const vec3 brown = vec3(98.0/255.0,34.0/255.0,31.0/255.0);
const vec3 black = vec3(7.0/255.0);
const vec3 deepred = vec3(231.0/255.0,52.0/255.0,39.0/255.0);
const vec3 orangecrimson = vec3(227.0/255.0,85.0/255.0,44.0/255.0);
const vec3 blueishgreen = vec3(79.0/255.0,161.0/255.0,131.0/255.0);
const vec3 deepblue = vec3(25.0/255.0,19.0/255.0,125.0/255.0);

const vec3 greenishblue = vec3(66.0/255.0,142.0/255.0,129.0/255.0);
const vec3 violetred = vec3(201.0/255.0,51.0/255.0,83.0/255.0);
const vec3 darkviolet = vec3(117.0/255.0,28.0/255.0,120.0/255.0);
const vec3 cayanblue = vec3(45.0/255.0,91.0/255.0,155.0/255.0);
const vec3 indigoblue = purple;

const vec3 endofred = vec3(145.0/255.0,34.0/255.0,84.0/255.0);
const vec3 steely = vec3(89.0/255.0,87.0/255.0,130.0/255.0);
const vec3 pearlyblue = vec3(45.0/255.0,91.0/255.0,155.0/255.0);
const vec3 darkred = vec3(148.0/255.0,33.0/255.0,23.0/255.0);

const vec3 brightblue = vec3(25.0/255.0,19.0/255.0,125.0/255.0);
const vec3 rosyorange = vec3(234.0,134.0,54.0);
const vec3 ultramarineblue = vec3(45.0/255.0,91.0/255.0,155.0/255.0);
const vec3 blueviolet = vec3(69.0/255.0,23.0/255.0,120.0/255.0);

const vec3 ultraviolet = vec3(102.0/255.0,25.0/255.0,68.0/255.0);
const vec3 infrared = vec3(148.0/255.0,33.0/255.0,23.0/255.0);
const vec3 yellowwhite = vec3(238.0/255.0,239.0/255.0,149.0/255.0);


vec4 colorForAuthorAndNote(int author, int note)	{
	vec4	inputPixelColor = vec4(0.0);
	inputPixelColor.a = 1.0;
	//	newton
	if (author == 0)	{
		if (note == 0)
			inputPixelColor.rgb = red;
		else if (note == 1)
			inputPixelColor.rgb = red;
		else if (note == 2)
			inputPixelColor.rgb = orange;
		else if (note == 3)
			inputPixelColor.rgb = orange;
		else if (note == 4)
			inputPixelColor.rgb = yellow;
		else if (note == 5)
			inputPixelColor.rgb = green;
		else if (note == 6)
			inputPixelColor.rgb = green;
		else if (note == 7)
			inputPixelColor.rgb = blue;
		else if (note == 8)
			inputPixelColor.rgb = blue;
		else if (note == 9)
			inputPixelColor.rgb = indigo;
		else if (note == 10)
			inputPixelColor.rgb = indigo;
		else if (note == 11)
			inputPixelColor.rgb = violet;
	}
	//	castel
	else if (author == 1)	{
		if (note == 0)
			inputPixelColor.rgb = blue;
		else if (note == 1)
			inputPixelColor.rgb = bluegreen;
		else if (note == 2)
			inputPixelColor.rgb = green;
		else if (note == 3)
			inputPixelColor.rgb = olivegreen;
		else if (note == 4)
			inputPixelColor.rgb = yellow;
		else if (note == 5)
			inputPixelColor.rgb = yelloworange;
		else if (note == 6)
			inputPixelColor.rgb = orange;
		else if (note == 7)
			inputPixelColor.rgb = red;
		else if (note == 8)
			inputPixelColor.rgb = crimson;
		else if (note == 9)
			inputPixelColor.rgb = violet;
		else if (note == 10)
			inputPixelColor.rgb = agate;
		else if (note == 11)
			inputPixelColor.rgb = indigo;
	}
	//	field
	else if (author == 2)	{
		if (note == 0)
			inputPixelColor.rgb = blue;
		else if (note == 1)
			inputPixelColor.rgb = blue;
		else if (note == 2)
			inputPixelColor.rgb = purple;
		else if (note == 3)
			inputPixelColor.rgb = purple;
		else if (note == 4)
			inputPixelColor.rgb = red;
		else if (note == 5)
			inputPixelColor.rgb = orange;
		else if (note == 6)
			inputPixelColor.rgb = orange;
		else if (note == 7)
			inputPixelColor.rgb = yellow;
		else if (note == 8)
			inputPixelColor.rgb = yellow;
		else if (note == 9)
			inputPixelColor.rgb = yellowgreen;
		else if (note == 10)
			inputPixelColor.rgb = yellowgreen;
		else if (note == 11)
			inputPixelColor.rgb = green;
	}
	//	jameson
	else if (author == 3)	{
		if (note == 0)
			inputPixelColor.rgb = red;
		else if (note == 1)
			inputPixelColor.rgb = redorange;
		else if (note == 2)
			inputPixelColor.rgb = orange;
		else if (note == 3)
			inputPixelColor.rgb = orangeyellow;
		else if (note == 4)
			inputPixelColor.rgb = yellow;
		else if (note == 5)
			inputPixelColor.rgb = green;
		else if (note == 6)
			inputPixelColor.rgb = greenblue;
		else if (note == 7)
			inputPixelColor.rgb = blue;
		else if (note == 8)
			inputPixelColor.rgb = bluepurple;
		else if (note == 9)
			inputPixelColor.rgb = purple;
		else if (note == 10)
			inputPixelColor.rgb = purpleviolet;
		else if (note == 11)
			inputPixelColor.rgb = violet;
	}
	//	seemann
	else if (author == 4)	{
		if (note == 0)
			inputPixelColor.rgb = carmine;
		else if (note == 1)
			inputPixelColor.rgb = scarlet;
		else if (note == 2)
			inputPixelColor.rgb = orange;
		else if (note == 3)
			inputPixelColor.rgb = yelloworange;
		else if (note == 4)
			inputPixelColor.rgb = yellow;
		else if (note == 5)
			inputPixelColor.rgb = green;
		else if (note == 6)
			inputPixelColor.rgb = greenblue;
		else if (note == 7)
			inputPixelColor.rgb = blue;
		else if (note == 8)
			inputPixelColor.rgb = indigo;
		else if (note == 9)
			inputPixelColor.rgb = violet;
		else if (note == 10)
			inputPixelColor.rgb = brown;
		else if (note == 11)
			inputPixelColor.rgb = black;
	}
	//	rimington
	else if (author == 5)	{
		if (note == 0)
			inputPixelColor.rgb = deepred;
		else if (note == 1)
			inputPixelColor.rgb = crimson;
		else if (note == 2)
			inputPixelColor.rgb = orangecrimson;
		else if (note == 3)
			inputPixelColor.rgb = orange;
		else if (note == 4)
			inputPixelColor.rgb = yellow;
		else if (note == 5)
			inputPixelColor.rgb = yellowgreen;
		else if (note == 6)
			inputPixelColor.rgb = green;
		else if (note == 7)
			inputPixelColor.rgb = blueishgreen;
		else if (note == 8)
			inputPixelColor.rgb = bluegreen;
		else if (note == 9)
			inputPixelColor.rgb = indigo;
		else if (note == 10)
			inputPixelColor.rgb = deepblue;
		else if (note == 11)
			inputPixelColor.rgb = violet;
	}
	//	bishop
	else if (author == 6)	{
		if (note == 0)
			inputPixelColor.rgb = red;
		else if (note == 1)
			inputPixelColor.rgb = scarlet;
		else if (note == 2)
			inputPixelColor.rgb = orange;
		else if (note == 3)
			inputPixelColor.rgb = yelloworange;
		else if (note == 4)
			inputPixelColor.rgb = yellow;
		else if (note == 5)
			inputPixelColor.rgb = yellowgreen;
		else if (note == 6)
			inputPixelColor.rgb = green;
		else if (note == 7)
			inputPixelColor.rgb = greenishblue;
		else if (note == 8)
			inputPixelColor.rgb = blue;
		else if (note == 9)
			inputPixelColor.rgb = indigo;
		else if (note == 10)
			inputPixelColor.rgb = violet;
		else if (note == 11)
			inputPixelColor.rgb = violetred;
	}
	//	helmholtz
	else if (author == 7)	{
		if (note == 0)
			inputPixelColor.rgb = yellow;
		else if (note == 1)
			inputPixelColor.rgb = green;
		else if (note == 2)
			inputPixelColor.rgb = greenishblue;
		else if (note == 3)
			inputPixelColor.rgb = cayanblue;
		else if (note == 4)
			inputPixelColor.rgb = indigoblue;
		else if (note == 5)
			inputPixelColor.rgb = violet;
		else if (note == 6)
			inputPixelColor.rgb = endofred;
		else if (note == 7)
			inputPixelColor.rgb = red;
		else if (note == 8)
			inputPixelColor.rgb = red;
		else if (note == 9)
			inputPixelColor.rgb = red;
		else if (note == 10)
			inputPixelColor.rgb = redorange;
		else if (note == 11)
			inputPixelColor.rgb = orange;
	}
	//	scriabin
	else if (author == 8)	{
		if (note == 0)
			inputPixelColor.rgb = red;
		else if (note == 1)
			inputPixelColor.rgb = violet;
		else if (note == 2)
			inputPixelColor.rgb = yellow;
		else if (note == 3)
			inputPixelColor.rgb = steely;
		else if (note == 4)
			inputPixelColor.rgb = pearlyblue;
		else if (note == 5)
			inputPixelColor.rgb = darkred;
		else if (note == 6)
			inputPixelColor.rgb = brightblue;
		else if (note == 7)
			inputPixelColor.rgb = rosyorange;
		else if (note == 8)
			inputPixelColor.rgb = purple;
		else if (note == 9)
			inputPixelColor.rgb = green;
		else if (note == 10)
			inputPixelColor.rgb = steely;
		else if (note == 11)
			inputPixelColor.rgb = pearlyblue;
	}
	//	klein
	else if (author == 9)	{
		if (note == 0)
			inputPixelColor.rgb = darkred;
		else if (note == 1)
			inputPixelColor.rgb = red;
		else if (note == 2)
			inputPixelColor.rgb = redorange;
		else if (note == 3)
			inputPixelColor.rgb = orange;
		else if (note == 4)
			inputPixelColor.rgb = yellow;
		else if (note == 5)
			inputPixelColor.rgb = yellowgreen;
		else if (note == 6)
			inputPixelColor.rgb = green;
		else if (note == 7)
			inputPixelColor.rgb = bluegreen;
		else if (note == 8)
			inputPixelColor.rgb = blue;
		else if (note == 9)
			inputPixelColor.rgb = blueviolet;
		else if (note == 10)
			inputPixelColor.rgb = violet;
		else if (note == 11)
			inputPixelColor.rgb = darkviolet;
	}
	//	aeppli
	else if (author == 10)	{
		if (note == 0)
			inputPixelColor.rgb = red;
		else if (note == 1)
			inputPixelColor.rgb = red;
		else if (note == 2)
			inputPixelColor.rgb = orange;
		else if (note == 3)
			inputPixelColor.rgb = orange;
		else if (note == 4)
			inputPixelColor.rgb = yellow;
		else if (note == 5)
			inputPixelColor.rgb = yellow;
		else if (note == 6)
			inputPixelColor.rgb = green;
		else if (note == 7)
			inputPixelColor.rgb = bluegreen;
		else if (note == 8)
			inputPixelColor.rgb = bluegreen;
		else if (note == 9)
			inputPixelColor.rgb = ultramarineblue;
		else if (note == 10)
			inputPixelColor.rgb = violet;
		else if (note == 11)
			inputPixelColor.rgb = purple;
	}
	//	belmont
	else if (author == 11)	{
		if (note == 0)
			inputPixelColor.rgb = red;
		else if (note == 1)
			inputPixelColor.rgb = redorange;
		else if (note == 2)
			inputPixelColor.rgb = orange;
		else if (note == 3)
			inputPixelColor.rgb = yelloworange;
		else if (note == 4)
			inputPixelColor.rgb = yellow;
		else if (note == 5)
			inputPixelColor.rgb = yellowgreen;
		else if (note == 6)
			inputPixelColor.rgb = green;
		else if (note == 7)
			inputPixelColor.rgb = bluegreen;
		else if (note == 8)
			inputPixelColor.rgb = blue;
		else if (note == 9)
			inputPixelColor.rgb = blueviolet;
		else if (note == 10)
			inputPixelColor.rgb = violet;
		else if (note == 11)
			inputPixelColor.rgb = violetred;
	}
	//	zieverink
	else if (author == 12)	{
		if (note == 0)
			inputPixelColor.rgb = yellowgreen;
		else if (note == 1)
			inputPixelColor.rgb = green;
		else if (note == 2)
			inputPixelColor.rgb = bluegreen;
		else if (note == 3)
			inputPixelColor.rgb = blue;
		else if (note == 4)
			inputPixelColor.rgb = indigo;
		else if (note == 5)
			inputPixelColor.rgb = violet;
		else if (note == 6)
			inputPixelColor.rgb = ultraviolet;
		else if (note == 7)
			inputPixelColor.rgb = infrared;
		else if (note == 8)
			inputPixelColor.rgb = red;
		else if (note == 9)
			inputPixelColor.rgb = orange;
		else if (note == 10)
			inputPixelColor.rgb = yellowwhite;
		else if (note == 11)
			inputPixelColor.rgb = yellow;
	}
	return inputPixelColor;
}

vec3 rgb2hsv(vec3 c)	{
	vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
	//vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
	//vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
	vec4 p = c.g < c.b ? vec4(c.bg, K.wz) : vec4(c.gb, K.xy);
	vec4 q = c.r < p.x ? vec4(p.xyw, c.r) : vec4(c.r, p.yzx);
	
	float d = q.x - min(q.w, q.y);
	float e = 1.0e-10;
	return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}

vec3 hsv2rgb(vec3 c)	{
	vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
	vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
	return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}

vec4 relatedColorForMode(vec4 inColor, int colorMode, float index, int colorCount)	{
	vec3		outColor = rgb2hsv(inColor.rgb);
	float		variation = 0.3236;	//	1/5 the golden ratio
	
	//	Basic complimentary – saturation and brightness variations on two fixed 180 degree opposite hues
	if (colorMode == 0)	{
		if (mod(index, 2.0) >= 1.0)	{
			outColor.r = outColor.r + 0.5;
			outColor.r = outColor.r - floor(outColor.r);
		}
		
		outColor.g = outColor.g - variation * floor(index / 2.0);
		
		if (outColor.g < 0.1)	{
			outColor.g = outColor.g + variation * floor(index / 2.0);
			outColor.g = outColor.g - floor(outColor.g);
		}
		
		outColor.b = outColor.b - variation * floor(index / 4.0);
		if (outColor.b < 0.2)	{
			outColor.b = outColor.b + variation * floor(index / 4.0);
			outColor.b = outColor.b - floor(outColor.b);
		}
	}
	//	Split complimentary – saturation and brightness variations on a 3 fixed 120 degree hues
	else if (colorMode == 1)	{
		float divisor = 3.0;
		float ratio = 0.45;
		if (mod(index, 3.0) >= 2.0)	{
			outColor.r = outColor.r - ratio;
		}
		else if (mod(index, 3.0) >= 1.0)	{
			outColor.r = outColor.r + ratio;
		}
		
		//outColor.g = outColor.g + variation * floor(index / divisor);
		
		if (mod(index, 5.0) >= 3.0)	{
			outColor.g = outColor.g - variation;
			outColor.g = outColor.g - floor(outColor.g);
		}
		outColor.b = outColor.b - variation * floor(index / (divisor));
		if (outColor.b < 0.1)	{
			outColor.b = outColor.b + variation * floor(index / (divisor));
			outColor.b = outColor.b - floor(outColor.b);
		}
	}
	//	Compound complimentary – a combination of shades, complimentary and analogous colors with slight shifts
	else if (colorMode == 2)	{
		if (mod(index, 3.0) >= 2.0)	{
			outColor.r = outColor.r + 0.5;
			outColor.r = outColor.r + variation * index * 1.0 / float(colorCount - 1) / 4.0;
		}
		else	{
			outColor.r = outColor.r + variation * index * 1.0 / float(colorCount - 1);
		}
		outColor.r = outColor.r - floor(outColor.r);
		
		
		if (mod(index, 2.0) >= 1.0)	{
			outColor.g = outColor.g + index * variation / 2.0;
		}
		else if (mod(index, 3.0) >= 2.0)	{
			outColor.g = outColor.g - variation / 2.0;
		}
		else	{
			outColor.g = outColor.g - index * variation / float(colorCount - 1);
		}
		if (outColor.g > 1.0)	{
			outColor.g = outColor.g - floor(outColor.g);
		}
	}
	//	Spectrum – hue shifts based on number of colors with minor saturation shifts
	else if (colorMode == 3)	{
		outColor.r = outColor.r + index * 1.0 / float(colorCount);
		if (mod(index, 3.0) >= 2.0)	{
			outColor.g = outColor.g - variation / 2.0;
			outColor.g = outColor.g - floor(outColor.g);
		}
		else if (mod(index, 4.0) >= 3.0)	{
			outColor.g = outColor.g + variation / 2.0;
			//outColor.g = outColor.g - floor(outColor.g);
		}
	}
	//	Shades – saturation and brightness variations on a single fixed hue
	else if (colorMode == 4)	{
		if (mod(index, 2.0) >= 1.0)	{
			outColor.b = outColor.b - (index * variation) / float(colorCount-1);
		}
		else	{
			outColor.b = outColor.b + (index * variation) / float(colorCount-1);
			outColor.b = outColor.b - floor(outColor.b);
		}
		if (outColor.b < 0.075)	{
			outColor.b = 1.0 - outColor.b * variation;
		}
		
		if (mod(index, 3.0) >= 2.0)	{
			outColor.g = outColor.g - (index * variation) / 2.0;
		}
		else if (mod(index, 4.0) >= 3.0)	{
			outColor.g = outColor.g + (index * variation) / 2.0;
		}
		
		if ((outColor.g > 1.0) || (outColor.g < 0.05))	{
			outColor.g = outColor.g - floor(outColor.g);
		}
	}
	//	Analogous – small hue and saturation shifts 
	else if (colorMode == 5)	{

		outColor.r = outColor.r + variation * index * 1.0 / float(colorCount - 1); 		

		if (mod(index, 3.0) >= 1.0)	{
			outColor.g = outColor.g - variation / 2.0;
			if (outColor.g < 0.0)	{
				outColor.g = outColor.g + variation / 2.0;
			}
			if (outColor.g > 1.0)	{
				outColor.g = outColor.g - floor(outColor.g);
			}
		}
	}
	//	Compound Analogous – similar to analogous but with negative hue shifts
	else if (colorMode == 6)	{
		if (mod(index, 3.0) >= 1.0)	{
			outColor.r = outColor.r + variation * index * 1.0 / float(colorCount - 1); 
		}
		else	{
			outColor.r = outColor.r - variation * index * 0.5 / float(colorCount - 1);	
		}
		if (mod(index, 3.0) >= 1.0)	{
			outColor.g = outColor.g - variation / 2.0;
			if (outColor.g < 0.0)	{
				outColor.g = outColor.g + variation / 2.0;
			}
			if (outColor.g > 1.0)	{
				outColor.g = outColor.g - floor(outColor.g);
			}
		}	
	}
	
	return vec4(hsv2rgb(outColor.rgb),inColor.a);
}

void main()	{
	vec4		inputPixelColor = vec4(0.0);
	vec4		colorsArray[12];
	int			colorsCount = 0;
	
	//	how many colors are active?
	if (note0)	{
		colorsArray[colorsCount] = (iAuthor == 0) ? relatedColorForMode(iBaseCustomColor,iColorMode,0.0,12) : colorForAuthorAndNote(iAuthor-1,0);
		++colorsCount;
	}
	if (note1)	{
		colorsArray[colorsCount] = (iAuthor == 0) ? relatedColorForMode(iBaseCustomColor,iColorMode,1.0,12) : colorForAuthorAndNote(iAuthor-1,1);
		++colorsCount;
	}
	if (note2)	{
		colorsArray[colorsCount] = (iAuthor == 0) ? relatedColorForMode(iBaseCustomColor,iColorMode,2.0,12) :  colorForAuthorAndNote(iAuthor-1,2);
		++colorsCount;
	}
	if (note3)	{
		colorsArray[colorsCount] = (iAuthor == 0) ? relatedColorForMode(iBaseCustomColor,iColorMode,3.0,12) :  colorForAuthorAndNote(iAuthor-1,3);
		++colorsCount;
	}
	if (note4)	{
		colorsArray[colorsCount] = (iAuthor == 0) ? relatedColorForMode(iBaseCustomColor,iColorMode,4.0,12) :  colorForAuthorAndNote(iAuthor-1,4);
		++colorsCount;
	}
	if (note5)	{
		colorsArray[colorsCount] = (iAuthor == 0) ? relatedColorForMode(iBaseCustomColor,iColorMode,5.0,12) :  colorForAuthorAndNote(iAuthor-1,5);
		++colorsCount;
	}
	if (note6)	{
		colorsArray[colorsCount] = (iAuthor == 0) ? relatedColorForMode(iBaseCustomColor,iColorMode,6.0,12) :  colorForAuthorAndNote(iAuthor-1,6);
		++colorsCount;
	}
	if (note7)	{
		colorsArray[colorsCount] = (iAuthor == 0) ? relatedColorForMode(iBaseCustomColor,iColorMode,7.0,12) :  colorForAuthorAndNote(iAuthor-1,7);
		++colorsCount;
	}
	if (note8)	{
		colorsArray[colorsCount] = (iAuthor == 0) ? relatedColorForMode(iBaseCustomColor,iColorMode,8.0,12) :  colorForAuthorAndNote(iAuthor-1,8);
		++colorsCount;
	}
	if (note9)	{
		colorsArray[colorsCount] = (iAuthor == 0) ? relatedColorForMode(iBaseCustomColor,iColorMode,9.0,12) :  colorForAuthorAndNote(iAuthor-1,9);
		++colorsCount;
	}
	if (note10)	{
		colorsArray[colorsCount] = (iAuthor == 0) ? relatedColorForMode(iBaseCustomColor,iColorMode,10.0,12) :  colorForAuthorAndNote(iAuthor-1,10);
		++colorsCount;
	}
	if (note11)	{
		colorsArray[colorsCount] = (iAuthor == 0) ? relatedColorForMode(iBaseCustomColor,iColorMode,11.0,12) :  colorForAuthorAndNote(iAuthor-1,11);
		++colorsCount;
	}
	
	if (colorsCount > 0)	{
		int		thisIndex = int(isf_FragNormCoord.x * float(colorsCount));
		inputPixelColor = colorsArray[thisIndex];
	}
	
	gl_FragColor = inputPixelColor;
}